package com.example;


import java.math.BigDecimal;

public class DoubleTest {


    public static void main(String[] args) throws Exception {

        float weightF = 2.4f;
        double weightD = 2.4d;
        int price = 3800;
        BigDecimal bigDecimalWeight = new BigDecimal(weightD);
        double doubleWeight = bigDecimalWeight.doubleValue();
        BigDecimal totalPrice1 = bigDecimalWeight.multiply(new BigDecimal(price));
        int totalPrice2 = (int) (doubleWeight * price);
        System.out.println("bigDecimalWeight = " + bigDecimalWeight + ",totalPrice1 = " + totalPrice1 + ",totalPrice2 = " + totalPrice2);


        float priceF = 18.90f;
        double priceD = 18.89;


        float priceFloat = Float.valueOf("18.9");
        int priceI = (int) (priceF * 100 * 1);
        int priceII = (int) (priceD * 100);
        int priceIII = (int) (priceFloat * 1000 * 1);

        System.out.println("priceI: " + priceI);
        System.out.println("priceII: " + priceII);
        System.out.println("priceIII: " + priceIII);

        System.out.println("priceIIII: " + getPriceToCent("18.89"));
        System.out.println("priceIIII: " + getPriceToCent("18.999"));
        System.out.println("priceIIII: " + getPriceToCent("188.99"));

    }

    public static int getPriceToCent(String price) {
        BigDecimal priceBigDecimal = new BigDecimal(price);
        BigDecimal result = priceBigDecimal.multiply(new BigDecimal("100"));
        return result.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
    }

}
